package IsSubsequence;


public class Solution {
    public boolean isSubsequence(String s, String t) {
        if (s.length()==0) return true;
        String temps=s.substring(0,1),tempt;
        int indexT=0,indexS=0;
        while (indexT<t.length()){
        	tempt=t.substring(indexT, indexT+1);
        	if (temps.equals(tempt)){
        		indexS++;
        		if (indexS==s.length()) return true;
        		temps=s.substring(indexS, indexS+1);
        	}
        	indexT++;
        	
        }
        return false;
        /*t=tt.toString();
        if (t.length()<s.length()) return false;
        int j=-1,i;
        int[] p=new int[s.length()];
        p[0]=0;
        for (i=1;i<s.length();i++){
        	while ((j>-1) && (s.charAt(j+1)!=s.charAt(i))) j=p[j];
        	if (s.charAt(j+1)==s.charAt(i)) j++;
        	p[i]=j;
        }
        j=-1;
        for (i=0;i<t.length();i++){
        	while ((j>0) && (s.charAt(j+1)!=t.charAt(i))) j=p[j];
        	if (s.charAt(j+1)==s.charAt(i)) j++;
        	if (j==s.length()-1) return true;
        } 
        return false;*/
        
    }
    public static void main(String[] args) {
    	Solution so=new Solution();
    	String s="abc";
    	String t="ahbgdc";
    	System.out.println(so.isSubsequence(s, t));
		
	}
}
